package org.springblade.modules.mes.base.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.mes.base.entity.LMSDetail;
import org.springblade.modules.mes.base.service.ILmsProductionOrderService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * LMS 生产订单
 *
 * @author BladeX
 * @since 2020-09-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("/lmsOrder")
@Api(value = "生产订单", tags = "生产订单")
public class LmsProducionOrderController extends BladeController {

	private final ILmsProductionOrderService lmsProductionOrderService;
	/**
	 * 详情
	 */
	@GetMapping("/detail")
	//@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "")
	public R<LMSDetail> detail(LMSDetail lmsDetail) {
		LMSDetail detail = lmsProductionOrderService.getOne(Condition.getQueryWrapper(lmsDetail));
		return R.data(detail);
	}

	/**
	 * 自定义分页 生产订单
	 */
	@GetMapping("/page")
	//@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入materialGroup")
	public R<IPage<LMSDetail>> page(LMSDetail lmsDetail, Query query) {
		IPage<LMSDetail> pages = lmsProductionOrderService.selectMaterialGroupPage(Condition.getPage(query), lmsDetail);
		return R.data(pages);
	}

	/**
	 * 新增 材料组
	 */
	@PostMapping("/save")
	//@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入materialGroup")
	public R save(@Valid @RequestBody LMSDetail lmsDetail) {
		boolean flag = lmsProductionOrderService.save(lmsDetail);
		return R.status(flag);
	}

	/**
	 * 修改 材料组
	 */
	@PostMapping("/update")
	//@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入materialGroup")
	public R update(@Valid @RequestBody LMSDetail lmsDetail) {
		boolean flag = lmsProductionOrderService.updateById(lmsDetail);
		return R.status(flag);
	}

	/**
	 * 删除 材料组
	 */
	@PostMapping("/remove")
	//@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		List<Long> idList = Func.toLongList(ids);
		boolean flag = lmsProductionOrderService.deleteLogic(idList);
		return R.status(flag);
	}
	@PostMapping("/pause")
	//@ApiOperationSupport(order = 7)
	@ApiOperation(value = "订单暂挂", notes = "传入ids")
	public R pause(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		List<Long> idList = Func.toLongList(ids);
		boolean flag = lmsProductionOrderService.pauseOrder(idList);
		return R.status(flag);
	}
}

